clear all; close all; clc;
R=100;
C=33e-6;
RC=R*C;
Tmod=10*RC;
T=RC/1000;
t=0:T:Tmod;

E=0*(t<Tmod/4)+3*(t>=Tmod/4);

U=nan(1,length(t));
dU=nan(1,length(t));

U(1)=E(1); dU(1)=0;
U2=U;

for k=2:length(t)
    U(k)=U(k-1)*dU(k-1)*T;
    dU(k)=(E(k)-U(k))/RC;
   
    U2(k) = (RC*U2(k-1)+E(k)*T)/(RC+T);
    end

    figure;
    plot(t,E,t,U,t,U2)
    xlabel('t,sec');
    ylabel('U,V');
